package com.rede.didiok.common.fallback;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import com.rede.didiok.common.dto.admin.SystemConfigDto;
import com.rede.didiok.common.dto.file.FileDto;
import com.rede.didiok.common.dto.file.PictureCategoryDto;
import com.rede.didiok.common.dto.file.PictureDto;
import com.rede.didiok.common.feign.FileFeignClient;
import com.rede.didiok.common.holder.RequestHolder;
import com.rede.didiok.common.utils.R;
import com.rede.didiok.common.utils.ResultUtil;


/**
 * 图片服务降级兜底方法【当服务不可用时会触发】
 *
 * @author: 陌溪
 * @create: 2020-10-03-20:54
 */
@Component
@Slf4j
public class FileFeignFallback implements FileFeignClient {

    @Override
    public String getPicture(String fileIds, String code) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，服务降级返回，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("获取图片服务降级返回");
    }

    @Override
    public String uploadPicsByUrl(FileDto fileVO) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，更新图片失败，服务降级返回，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("更新图片服务降级返回");
    }

    @Override
    public String initStorageSize(String adminUid, Long maxStorageSize) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，初始化网盘容量失败，服务降级返回，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，初始化网盘容量失败");
    }

    @Override
    public String editStorageSize(String adminUid, Long maxStorageSize) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，更新网盘容量失败，服务降级返回，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，更新网盘容量失败，服务降级返回");
    }

    @Override
    public String getStorageByAdminUid(List<String> adminUidList) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，获取网盘容量失败，服务降级返回，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，获取网盘容量失败，服务降级返回");
    }

    @Override
    public String getFileList(FileDto fileVO) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，获取图片列表失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，获取图片列表失败，服务降级返回");
    }

    @Override
    public Map<String, com.rede.didiok.common.dto.file.FileDto> getFileListMap(FileDto fileVO) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，获取图片列表失败，请求路径: {}", requestURL);
        return new HashMap<>();
    }

    @Override
    public String batchDeleteFileSystemConfig(SystemConfigDto systemConfigDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，删除素材失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，删除素材失败，服务降级返回");
    }

    /**
     * 查询指定条件下的文件列表
     *
     * @param fileDto
     * @return
     */
    @Override
    public R getFilePage(FileDto fileDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，查询指定条件下的文件列表失败，请求路径: {}", requestURL);
        return R.error("图片服务出现异常，查询指定条件下的文件列表失败");
    }

    /**
     * 根据 fileUidList 查询文件
     *
     * @param fileUidList
     * @return
     */
    @Override
    public R listFileByUids(List<String> fileUidList) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，根据 fileUidList 查询文件失败，请求路径: {}", requestURL);
        return R.error("图片服务出现异常，根据 fileUidList 查询文件失败");
    }

    /**
     * 获取任意榜单成员封面
     *
     * @return
     */
    @Override
    public R getTopOne() {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，获取任意榜单成员封面失败，请求路径: {}", requestURL);
        return R.error("图片服务出现异常，获取任意榜单成员封面失败");
    }

    /**
     * 获取图片列表
     *
     * @param pictureDto
     * @return
     */
    @Override
    public String getPicturePageList(PictureDto pictureDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，获取图片列表失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，获取图片列表失败");
    }

    /**
     * 增加图片
     *
     * @param pictureDtoList
     * @return
     */
    @Override
    public String addPicture(List<PictureDto> pictureDtoList) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，增加图片失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，增加图片失败");
    }

    /**
     * 删除图片
     *
     * @param pictureDto
     * @return
     */
    @Override
    public String deleteBatchPicture(PictureDto pictureDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，删除图片失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，删除图片失败");
    }

    /**
     * 通过图片Uid将图片设为封面
     *
     * @param pictureDto
     * @return
     */
    @Override
    public String setPictureCover(PictureDto pictureDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，通过图片Uid将图片设为封面失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，通过图片Uid将图片设为封面失败");
    }

    /**
     * 根据uid获取图片
     *
     * @param uid 图片uid
     * @return
     */
    @Override
    public R getPictureById(String uid) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，根据uid获取图片失败，请求路径: {}", requestURL);
        return R.error("图片服务出现异常，根据uid获取图片失败");
    }

    /**
     * 根据uid更新图片
     *
     * @param pictureDto 图片
     * @return
     */
    @Override
    public R updatePictureById(PictureDto pictureDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，根据uid更新图片失败，请求路径: {}", requestURL);
        return R.error("图片服务出现异常，根据uid更新图片失败");
    }

    /**
     * 获取图片分类列表
     *
     * @param pictureCategoryDto@return
     */
    @Override
    public String getPictureCategoryPageList(PictureCategoryDto pictureCategoryDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，获取图片分类列表失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，获取图片分类列表失败");
    }

    /**
     * 增加图片分类
     *
     * @param pictureCategoryDto@return
     */
    @Override
    public String addPictureSort(PictureCategoryDto pictureCategoryDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，增加图片分类失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，增加图片分类失败");
    }

    /**
     * 编辑图片分类
     *
     * @param pictureCategoryDto@return
     */
    @Override
    public String editPictureSort(PictureCategoryDto pictureCategoryDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，编辑图片分类失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，编辑图片分类失败");
    }

    /**
     * 删除图片分类
     *
     * @param pictureCategoryDto@return
     */
    @Override
    public String deletePictureSort(PictureCategoryDto pictureCategoryDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，删除图片分类失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，删除图片分类失败");
    }

    /**
     * 置顶图片分类
     *
     * @param pictureCategoryDto@return
     */
    @Override
    public String stickPictureSort(PictureCategoryDto pictureCategoryDto) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，置顶图片分类失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，置顶图片分类失败");
    }

    /**
     * 根据uid获取图片分类
     *
     * @param uid@return
     */
    @Override
    public String getPictureCategoryByUid(String uid) {
        HttpServletRequest request = RequestHolder.getRequest();
        StringBuffer requestURL = request.getRequestURL();
        log.error("图片服务出现异常，根据uid获取图片分类失败，请求路径: {}", requestURL);
        return ResultUtil.errorWithMessage("图片服务出现异常，根据uid获取图片分类失败");
    }
}
